package com.ksy.common.dialog;

import android.content.Context;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.view.View;
import android.widget.TextView;

import com.ksy.common.R;


/**
 * Created by Ksy.
 */

public class YesNoChooseDialog extends BottomDialog {


    private final String item1;
    private final String item2;
    private ClickListener onClickListener;

    public YesNoChooseDialog(@NonNull Context context, String item1, String item2) {
        super(context);
        this.item1 = item1;
        this.item2 = item2;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.common_layout_dialog_picker_yes_no_bottom);
        View dialog_cancel = findViewById(R.id.dialog_cancel);
        dialog_cancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dismiss();
            }
        });
        TextView tvItem1 = findViewById(R.id.dialog_item1);
        tvItem1.setText(item1);
        TextView tvItem2 = findViewById(R.id.dialog_item2);
        tvItem2.setText(item2);

        tvItem1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (onClickListener != null) {
                    onClickListener.choose(YesNoChooseDialog.this, 0);
                }
            }
        });
        tvItem2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (onClickListener != null) {
                    onClickListener.choose(YesNoChooseDialog.this, 1);
                }
            }
        });
    }


    public void setOnClickListener(ClickListener onClickListener) {
        this.onClickListener = onClickListener;
    }

    public interface ClickListener {
        void choose(BaseDialog dialog, int position);
    }


}
